package com.egg.basic.controller.feign;

import com.egg.basic.fegin.BasicCaptchaFeignClient;
import com.egg.basic.model.response.CaptchaInfo;
import com.egg.basic.service.captcha.CaptchaService;
import com.egg.common.core.model.controller.FeignController;
import com.egg.common.core.model.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author east
 */
@Slf4j
@Api(tags = FeignController.API_PREFIX + "验证码")
@RestController
@RequestMapping("/captcha/image")
public class FeignCaptchaController extends FeignController implements BasicCaptchaFeignClient {


    @Autowired
    private CaptchaService captchaService;


    @Override
    @ApiOperation(value = "创建图形验证码")
    @GetMapping("/create")
    public ResponseData<CaptchaInfo> captchaImageCreateGet() {
        CaptchaInfo captcha = captchaService.generate();
        return ResponseData.success(captcha);
    }

    @Override
    @ApiOperation(value = "验证图形验证码")
    @GetMapping("/verify")
    public ResponseData<Boolean> captchaImageVerifyGet(
            @ApiParam(value = "标识") @RequestParam(value = "id", required = false) String id
            , @ApiParam(value = "验证码") @RequestParam(value = "code", required = false) String code
    ) {
        return ResponseData.success(captchaService.verify(id, code));
    }


}
